import { createStore } from 'vuex'

export default createStore({
  state: {
    BookList: [],
  },
  getters: {
  },
  mutations: {
    addBookItem:function (state, obj) {
      if (obj.had) {
        state.BookList.map((item)=>{
          if (item.uuid === obj.data.uuid) {
            item.count = obj.data.count;
          }
        });
      } else {
        state.BookList.push(obj.data);
      }
    },
    delBookItem:function (state, uuid) {
      state.BookList.map((item)=>{
        if (item.uuid === uuid) {
          state.BookList.splice(state.BookList.indexOf(item), 1);
        }
      });
    },
    clearBookList: function (state) {
      state.BookList.length = 0;
    },
  },
  actions: {
  },
  modules: {
  }
})
